package com.tgy.JUC.Pool;

import java.util.concurrent.*;

/***
 * @ClassName: Demo2
 * @Description: 自定义线程池
 * @Auther: 送你一块二向箔
 * @Date: 14:07 2022/3/14
 * @version : V1.0
 */
public class Demo2 {
    public static void main(String[] args) {

        run1();
    }

    public static void run1() {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(2,
                6,
                3,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(10),//这里必须要指定
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());


        try {
//            for (int i = 0; i < 25; i++) {
//                poolExecutor.execute(()->{
//                    System.out.println(Thread.currentThread().getName());
//                });
//
//            }
            for (int i = 0; i < 25; i++) {
                poolExecutor.execute(new MyTask());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            poolExecutor.shutdown();
        }


    }

}
